package com.itboye.mengwu.data.repository;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.reflect.TypeToken;
import com.itboye.core.interfaces.ICompleteListener;
import com.itboye.core.utils.BaseErrorListener;
import com.itboye.core.utils.BaseSuccessReqListener;
import com.itboye.core.utils.ByJsonRequest.Builder;
import com.itboye.mengwu.data.interfaces.IDingdanXiangQing;
import com.itboye.mengwu.data.model.DingdanXiangQingBean;

public class DingdanRepository extends BaseNetRepository implements
		IDingdanXiangQing<DingdanXiangQingBean> {
	public static final String ShopCarDingDanAdd = "BY_Orders_add";// 8.2 生成订单
	public static final String ShopCarDingDanFenYe = "BY_Orders_query";// 8.3
																		// 分页查询
	public static final String ShopCarDingDanXiangQiang = "BY_Orders_detail";// 8.4
																				// 订单详情
	public static final String ShopCarDingDanQueRen = "BY_Orders_sure";// 8.5
																		// 确认收货
	public static final String ShopCarDelte = "BY_Orders_cancel";// 8.6 取消订单
	public static final String Fahuoxinxi = "BY_Orders_express";// 8.7 发货信息
	public static final String ShopCarCost = "BY_Freight_cost";// 8.8 运费计算
	String api = "100";

	public DingdanRepository(ICompleteListener listener) {
		super(listener);
	}

	/***
	 * 8.3 生成订单
	 */
	@Override
	public void add(DingdanXiangQingBean model) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<DingdanXiangQingBean>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("uid", model.getUid());
		params.put("order_code", model.getOrder_code());

		(new Builder<DingdanXiangQingBean>())
				.setTypeVerParamsAndReturnClass(ShopCarDingDanAdd, apiVer,
						params, type)
				.requestListener(
						new BaseSuccessReqListener<DingdanXiangQingBean>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	/***
	 * 8.6 删除订单
	 */
	@Override
	public void delete(DingdanXiangQingBean model) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<DingdanXiangQingBean>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("uid", model.getUid());
		params.put("order_code", model.getOrder_code());

		(new Builder<DingdanXiangQingBean>())
				.setTypeVerParamsAndReturnClass(ShopCarDelte, apiVer, params,
						type)
				.requestListener(
						new BaseSuccessReqListener<DingdanXiangQingBean>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/***
	 * 修改订单
	 */
	@Override
	public void update(DingdanXiangQingBean model) {
		// TODO Auto-generated method stub

	}

	/**
	 * 8.4查询订单详情
	 */
	@Override
	public void getInfo(DingdanXiangQingBean model) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<ArrayList<DingdanXiangQingBean>>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("id", model.getId());
		(new Builder<ArrayList<DingdanXiangQingBean>>())
				.setTypeVerParamsAndReturnClass(ShopCarDingDanXiangQiang,
						apiVer, params, type)
				.requestListener(
						new BaseSuccessReqListener<ArrayList<DingdanXiangQingBean>>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	/***
	 * 8.3 分页查询订单列表
	 */
	@Override
	public List<DingdanXiangQingBean> query(DingdanXiangQingBean model) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<ArrayList<DingdanXiangQingBean>>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("uid", model.getUid());
		params.put("status", model.getStatus());
		(new Builder<ArrayList<DingdanXiangQingBean>>())
				.setTypeVerParamsAndReturnClass(ShopCarDingDanFenYe, apiVer,
						params, type)
				.requestListener(
						new BaseSuccessReqListener<ArrayList<DingdanXiangQingBean>>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
		return null;
	}

	/***
	 * 8.5发货信息 确认订单
	 */
	@Override
	public void getQueRen(String uid, String order_code) {
		// TODO Auto-generated method stub

		Type type = new TypeToken<DingdanXiangQingBean>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("uid", uid);
		params.put("order_code", order_code);

		(new Builder<DingdanXiangQingBean>())
				.setTypeVerParamsAndReturnClass(ShopCarDingDanQueRen, apiVer,
						params, type)
				.requestListener(
						new BaseSuccessReqListener<DingdanXiangQingBean>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 8.7运费计算
	 */
	@Override
	public void getYunFei(String uid, String address_id, String cart_ids) {
		// TODO Auto-generated method stub

		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("uid", uid);
		params.put("address_id", address_id);
		params.put("cart_ids", cart_ids);

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(ShopCarCost, apiVer, params,
						type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

}
